package controller.user.order;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import model.DTO.OrderReceiveDTO;
import model.VO.OrderBackVO;
import service.Impl.OrderServiceImpl;
import util.GetJsonUtil;
import util.ResultUtil;

import java.io.IOException;

@WebServlet("/user/order/submit")
public class OrderSubmitController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        OrderReceiveDTO dto= (OrderReceiveDTO) GetJsonUtil.get(req,new OrderReceiveDTO());
        OrderServiceImpl service=new OrderServiceImpl();
        OrderBackVO vo=service.order(dto.getAmount(),dto.getPayMethod(),dto.getRemark(),dto.getType());
        String json= ResultUtil.getJSON(vo);
        resp.getWriter().write(json);
    }
}
